/**
 * 
 */
function Line(color, width)
{
	/**
	 * Initialising all the shape properties
	 */
	Shape.call(this, color, width);
	
	/**
	 * 
	 */
	this.A = new Point2D();
	
	/**
	 * 
	 */
	this.B = new Point2D();
	
	/**
	 * 
	 */
	this.initShape = function(x,y)
	{
		this.A.x = x;
		this.A.y = y;
		
		this.B.x = x;
		this.B.y = y;
		
		this.addPoint(this.A.x, this.A.y, 0);
		this.addPoint(this.B.x, this.B.y, 0);
	};
	
	/**
	 * 
	 */
	this.fillShape = function(x, y)
	{
		this.B.x = x;
		this.B.y = y;
		
		this.x[1] = x;
		this.y[1] = y;
	};
	
	/**
	 * 
	 */
	this.endShape = function()
	{
		this.flushBuffers();
		
		
		
		// y = mx+p
		
		const nb_points = 1;
		
		
		
		var m = (this.B.y - this.A.y) / (this.B.x - this.A.x);
		var p = this.A.y - m * this.A.x;
				
		this.addPoint(this.A.x, this.A.y, 0);
		
		if (this.A.x == this.B.x) // Vertical
		{
			if (this.A.y < this.B.y)
			{
				for (var i = this.A.y ; i < + this.B.y ; i+=nb_points)
				{
					this.addPoint(this.A.x, i, 10);
				}
			}
			else
			{
				for (var i = this.B.y ; i < + this.A.y ; i+=nb_points)
				{
					this.addPoint(this.A.x, i, 10);
				}
			}
		}
		else if (this.A.y == this.B.y) // Horizontal
		{
			if (this.A.x < this.B.x)
			{
				for (var i = this.A.x ; i < + this.B.x ; i+=nb_points)
				{
					this.addPoint(i, this.A.y, 10);
				}
			}
			else
			{
				for (var i = this.B.x ; i < + this.A.x ; i+=nb_points)
				{
					this.addPoint(i, this.A.y, 10);
				}
			}
		}
		else
		{
			if (this.A.x < this.B.x)
			{
				for (var i = this.A.x ; i < + this.B.x ; i+=nb_points)
				{
					if (this.A.y < this.B.y)
					{
						for (var j = this.A.y ; j < this.B.y ; j+=nb_points)
						{
							var y = m * i + p;
	
							if ((y >= j) && (y <= j + .99))
							{
								this.addPoint(i, j, 10);
							}
						}
					}
					else
					{
						for (var j = this.B.y ; j < this.A.y ; j+=nb_points)
						{
							var y = m * i + p;
	
							if ((y >= j) && (y <= j + .99))
							{
								this.addPoint(i, j, 10);
							}
						}
					}
				}
			}
			else
			{
				alert("Here");
				for (var i = this.B.x ; i < this.A.x ; i+=nb_points)
				{
					if (this.A.y < this.B.y)
					{
						for (var j = this.A.y ; j < this.B.y ; j+=nb_points)
						{
							var y = m * i + p;
	
							if ((y >= j) && (y <= j + .99))
							{
								this.addPoint(i, y, 10);
							}
						}
					}
					else
					{
						for (var j = this.B.y ; j < this.A.y ; j+=nb_points)
						{
							var y = m * i + p;
	
							if ((y >= j) && (y <= j + .99))
							{
								this.addPoint(i, y, 10);
							}
						}
					}
				}
			}
			
		}
		
		this.addPoint(this.B.x, this.B.y, 0);
		
		
		this.addToCache();
	};
	
	this.rotate = function(degre)
    {
		this.cacheCanvas.width = this.cacheCanvas.width;
    	
    	// translate context to center of canvas
        this.ctx.translate(this.cacheCanvas.width / 2, this.cacheCanvas.height / 2);

        // rotate 90 degrees clockwise
        this.ctx.rotate(Math.PI / 2);
        
        // translate it back
        this.ctx.translate(-this.cacheCanvas.width / 2, -this.cacheCanvas.height / 2);
        
        this.ctx.strokeStyle = this.color.toString();
    	this.ctx.lineWidth = this.width;
    	this.ctx.lineJoin = "round";
    	
    	var theta = 90;
    	
    	var x_offset = getMin(this.x);
    	var y_offset = getMin(this.y);
    	
    	for (var i = 0 ; i < this.x.length ; i++)
    	{
    		
    		
    		
    		// Update canvas
	    	this.ctx.beginPath();
	    	this.ctx.moveTo(this.x[i], this.y[i]);
	    	this.ctx.lineTo(this.x[i+1], this.y[i+1]);
			
	    	this.ctx.closePath();
	    	this.ctx.stroke();
	    	
	    	// Update coordinate
    	    var x = this.x[i] * Math.cos(theta) - this.y[i] * Math.sin(theta);
    	    var y = this.x[i] * Math.sin(theta) + this.y[i] * Math.cos(theta);
    	    
    	    x += this.cacheCanvas.width;
    	    y += this.cacheCanvas.height;
    	    
    	    this.x[i] = x;
    	    this.y[i] = y;
    	}
    	
    };
	
	
}